package com.newtouch.bxzs.database.synchronize.batch.writer;

import com.newtouch.bxzs.database.synchronize.mapper.ProductMapper;
import com.newtouch.bxzs.database.synchronize.model.SynProductVO;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 产品数据入库
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/2/3 9:22</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
@SuppressWarnings("unchecked")
public class WriterProduct {

    @Autowired
    private ProductMapper productMapper;

    /**
     * 同步产品和附加险信息
     * @return ItemWriter
     */
    public ItemWriter<SynProductVO> addProduct(){
        return list -> {
            productMapper.saveProduct((List<SynProductVO>) list,new Date());
            productMapper.saveAdditional((List<SynProductVO>) list,new Date());
        };
    }
}
